package com.yanqu.road.server.cmd.cricket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cricketcourt.CrossCricketCourtMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CRICKET_HOT_BATTLE_LOG_DETAIL, desc = "热门战报详情")
public class CrossCricketBattleLogDetailCmd extends CrossCommand {

    private long id;

    private int type;

    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CricketBattleLogDetailReqMsg reqMsg = CricketProto.CricketBattleLogDetailReqMsg.parseFrom(packet.getBytes());
        id = reqMsg.getId();
        type = reqMsg.getType();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        if (type != 1) {
            return;
        }
        ret = CrossCricketCourtMgr.battleLogDetail(serverId, userId, id);
    }

    @Override
    public void sendData() {
        if (ret != 0) {
            CricketProto.CricketBattleLogDetailRespMsg.Builder respMsg = CricketProto.CricketBattleLogDetailRespMsg.newBuilder();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, userId, YanQuMessageUtils.buildMessage(Protocol.U_CRICKET_BATTLE_LOG_DETAIL, respMsg));
        }
    }
}
